<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
      <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>

</head>
<style  type="text/css" media="screen">
.total{
    width:100%;
    height: 100%;
    background-color: #B3B3B3;
    position: fixed;
    top:0px;
    opacity:0.5;
    margin:0px;
    z-index: 2;
    display:none;
}    
.add{
    width:400px;
    height:300px;
    background-color: #fff;
    position:fixed;
    top:50px;
    left:30%;
    border-radius: 5px;
z-index: 300;
display: none;
}
.add span
{
    float:right;
    font-size: 30px;
    margin-top: 10px;
    margin-right: 20px;
    color:#666;
    cursor: pointer;
}
.add span:hover
{
    color:#aaa;
}
.add p
{
    font-size: 18px;
    float:left;
    margin-top: 40px;
    margin-left:170px;
    color:#000;
    font-family: '微软雅黑';
    text-align: center;

}
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 50px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
    border-radius: 5px;
    float:left;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}
</style>
<body>
<div class="total">
</div>
<div class="add" id="add">
<span onclick="ad()">×</span>
<p>增加选择题</p>
<form id="myformadd">
<table  class="addtab">
<tr><th><i class="require-red">*</i>题目：</th><td><input  name='judgeProblemTitle' type='text'  placeholder="题目"></td></tr>
<tr><th><i class="require-red">*</i>正确选项：</th><td><input  name='judgeProblemRight' type='text'  placeholder="正确选项"></td></tr>
<tr><th><i class="require-red">*</i>所属类型：</th><td><select  name="problemClassId">
         <c:forEach items="${classdata }" var="x">
                  <option value="${x.problemClassId}">${x.problemClassName }</option>
         </c:forEach>
</select></td></tr>
</table>
<input class="btn btn-primary btn6 btn12 suba" name="sub" value="添加" type="button" style="margin-left:140px;margin-top:20px">
</form>

</div>
<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看判断题</p>
<div class="container clearfix" style="width:100%">
    <div class="main-wrap">
        <div class="search-wrap">
        	<div class="search-content">
        	<form enctype="multipart/form-data" id="myform">
        	 <table class="search-tab">
        	 	<th width="90" style="font-size:16px">导入题库:</th>
        	 	<td><input type="file" name="file" /></td>
        	 	 <td><button type="button" class="btn btn-primary" onclick="upload()">导入题库</button></td>
        	 	 <td><button type="button" class="btn btn-success" onclick="window.location.href='${pageContext.request.contextPath}/public/moban/judge.csv'">下载模板</button></td>
        	 </form>
        	 
        	 <form id="classform" action="${pageContext.request.contextPath}/judge/searchjudge.action" method="post">
        	 	<th width="150px" style="font-size:16px">选择分类:</th>
        	 	<td>
        	 	<select name="problemClassId" style="width:120px;height:30px;border-radius:2%">
         			<option value="0">全部</option>
                    <c:forEach items="${classdata }" var="x">
                     <option value="${x.problemClassId}">${x.problemClassName }</option>
                    </c:forEach>
                  </select>
				</td>
				<td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
        	 	</table>
        	 </form>
        	</div>
        </div>
        <div class="result-wrap" >
               <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" onclick="ad()"><i class="icon-font"></i>新增题目</a>
                    </div>
                </div>
                <div class="result-content" id="app" >
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th>题目ID</th>
                            <th>题目</th>
                            <th>正确选项</th>
                            <th>所属分类</th>
                            <th>操作</th>
                        </tr>
                      <c:forEach items="${pageinfo.list}" var="v">
                        <tr >
                            <td>${v.judgeProblemId}</td>
                            <td><input style="height:30px;width:100%;" type="text" name="judgeProblemTitle" value="${v.judgeProblemTitle}" onchange="upd(${v.judgeProblemId},this.value,'judgeProblemTitle')" ></td>
                            <td><input style="height:30px;width:100%;" type="text" name="judgeProblemRight" value="${v.judgeProblemRight}" onchange="upd(${v.judgeProblemId},this.value,'judgeProblemRight')" ></td>
                            <td><select style="height: 30px;width:100%;" name="problemClassId" onchange="upd(${v.judgeProblemId},this.value,'problemClassId')">
                            	<option value="${v.problemClassId}">${v.problemClass.problemClassName}</option>
                            	<c:forEach items="${classdata }" var="x">
                            	<option value="${x.problemClassId}">${x.problemClassName }</option>
                            	</c:forEach>
                            	</select>
                            </td>
                         
                            <td>
                            <button type="button" class="btn btn-danger" onclick="dele(${v.judgeProblemId})">删除</button>
                            </tr>
  					</c:forEach>
                    </table>
                </div>
                </div>
               <div class="row">
				<div class="col-md-6">当前${pageinfo.getPageNum() }页,总${pageinfo.getPages() }
				页,总${pageinfo.getTotal()}条记录</div>
                <div class="col-md-6">
				<nav aria-label="Page navigation">
				<%if(session.getAttribute("problemClassId")==null){ %>
				<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/judge/jugeproblem.action?pn=1">首页</a></li>
					<c:if test="${pageInfo.hasPreviousPage }">
						<li><a href="${pageContext.request.contextPath}/judge/jugeproblem.action?pn=${pageInfo.pageNum-1}"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>


					<c:forEach items="${pageinfo.navigatepageNums }" var="page_Num">
						<c:if test="${page_Num == pageinfo.pageNum }">
							<li class="active"><a href="#">${page_Num }</a></li>
						</c:if>
						<c:if test="${page_Num != pageinfo.pageNum }">
							<li><a href="${pageContext.request.contextPath}/judge/jugeproblem.action?pn=${page_Num }">${page_Num }</a></li>
						</c:if>

					</c:forEach>
					<c:if test="${pageinfo.hasNextPage }">
						<li><a href="${pageContext.request.contextPath}/judge/jugeproblem.action?pn=${pageinfo.pageNum+1 }"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/judge/jugeproblem.action?pn=${pageinfo.pages}">末页</a></li>
				</ul>
				<%} else{ %>
								<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/judge/searchjudge.action?pn=1&problemClassId=<%=session.getAttribute("problemClassId") %>">首页</a></li>
					<c:if test="${pageInfo.hasPreviousPage }">
						<li><a href="${pageContext.request.contextPath}/judge/searchjudge.action?pn=${pageInfo.pageNum-1}&problemClassId=<%=session.getAttribute("problemClassId") %>"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>


					<c:forEach items="${pageinfo.navigatepageNums }" var="page_Num">
						<c:if test="${page_Num == pageinfo.pageNum }">
							<li class="active"><a href="#">${page_Num }</a></li>
						</c:if>
						<c:if test="${page_Num != pageinfo.pageNum }">
							<li><a href="${pageContext.request.contextPath}/judge/searchjudge.action?pn=${page_Num }&problemClassId=<%=session.getAttribute("problemClassId") %>">${page_Num }</a></li>
						</c:if>

					</c:forEach>
					<c:if test="${pageinfo.hasNextPage }">
						<li><a href="${pageContext.request.contextPath}/judge/searchjudge.action?pn=${pageinfo.pageNum+1 }&problemClassId=<%=session.getAttribute("problemClassId") %>"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/judge/searchjudge.action?pn=${pageinfo.pages}&problemClassId=<%=session.getAttribute("problemClassId") %>">末页</a></li>
				</ul>
				
				<%
				session.removeAttribute("problemClassId");} %>
				</nav>
			</div>
			</div>

    </div>
</div>

</body>
<script type="text/javascript">
        
function ad()
{
    $('.total').toggle(500);
    $('#add').toggle(1000);

}

function upload()
{
	 var formData = new FormData($("#myform")[0]);//获取表单数据        
     $.ajax({
          url: "${pageContext.request.contextPath}/judge/uploadjudge.action",//提交地址
          type: 'POST',
          data: formData,
          async: false,
          cache: false,
          contentType: false,
          processData: false,
          success: function (returndata) {
           if(returndata.code==1){
               layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:2000},function(){
                   location.reload(); 
                 });
           }
           else
           layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
          },
          error: function (returndata) {
           layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

      }
     });     
	
	}

function dele(id)
{
	$.get("${pageContext.request.contextPath}/judge/deletejudge.action",{id:id},function(returndata){
		if(returndata.code==1)
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
}
function upd(id,value,column)
{
	$.post("${pageContext.request.contextPath}/judge/updatejudge.action",{id:id,value:value,column:column},function(returndata){
		if(returndata.code==1)
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000});  
	});
}


$('.suba').click(function()
    {
    var judgeProblemTitle=$('input[name=judgeProblemTitle]');
	var judgeProblemRight=$('input[name=judgeProblemRight]');
    if(judgeProblemTitle.val()=="")
    {
        layer.msg('题目不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        judgeProblemTitle.focus();
        return ;
    }
    
    if(judgeProblemRight.val()=="")
    {
        layer.msg('正确选项不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        selectProblemRightoption.focus();
        return ;
    }


    var formData=$("#myformadd").serialize(); 
      $.ajax({
           url: "${pageContext.request.contextPath}/judge/insertjudge.action",//提交地址
           type: 'POST',
           data: formData,
           async: false,
           cache: false,
           processData: false,
           success: function (returndata) {
            if(returndata.code==1){
              layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
            }
            else
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
           },
           error: function (returndata) {
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

       }
      });     

    });
</script>
</html>